﻿
using KinonekoSoftware.CodariaDB.Documents.Index;

namespace KinonekoSoftware.CodariaDB.IO
{
    public sealed class InstanceCacheResourceFinder : ResourceFinder
    {
        public override void GetResources(ICollection<Resource> collection, IRepository repository)
        {
            var database = repository.Get<InstanceCache>(CollectionNames.Cache_InstanceDB);

            foreach (var cache in database.FindAll())
            {
                if (!string.IsNullOrEmpty(cache.Avatar))
                {
                    collection.Add(new Resource
                    {
                        ImageID = cache.Avatar,
                        Type    = ResourceType.Avatar,
                    });
                }

                if (!string.IsNullOrEmpty(cache.Cover))
                {
                    collection.Add(new Resource
                    {
                        ImageID = cache.Cover,
                        Type    = ResourceType.Image,
                        Usage   = true,
                    });
                }
            }
            
        }
    }
}